<template>
  <div>
    <form action="/">
      <van-search
        v-model="value"
        @cancel="$router.back()"
        @search="onSearch"
        show-action
        placeholder="请输入搜索关键词"
      />
    </form>
    <van-cell-group v-show="list.lenght !== 0">
      <van-cell
        @click="addFn(item.communityName, item.community)"
        v-for="(item, index) in list"
        :key="index"
        :title="item.communityName"
      />
    </van-cell-group>
  </div>
</template>

<script>
import {community } from '@/api/article'
import { getCityname, getCitycode } from '@/utils/storage'
export default {
  async created() {
    // const {
    //   body: { value }
    // } = await areaIhfo(localStorage.getItem('city'))
    // console.log(value);
    this.code = getCitycode()
    // console.log(getCitycode())
  },
  data() {
    return {
      value: '',
      code: '',
      list: []
    }
  },
  methods: {
    async onSearch() {
      const {body} = await community(this.value, this.code)
      // console.log(body)
      if (body.length === 0) {
        this.$toast.fail(`请输入${getCityname()}的正确小区`)
      }
      this.list = body
      // console.log(this.list.length)
    },
    addFn(communityName, community) {
      this.$router.push({
        path: '/gorent',
        query: {
          communityName: communityName,
          community: community
        }
      })
    }
  }
}
</script>

<style></style>
